<template>
  <div class="comment">
    <!-- 按钮 -->
    <div class="btns">
        <el-form size="small" inline style="text-align:center">
            <el-form-item label="主题">
              <el-input v-model="param.id"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="success" size="small" icon="el-icon-search" @click="loadComments">搜索</el-button>
            </el-form-item>
        </el-form>
        <el-button size="small" type="primary" @click="toAddHandler">新增</el-button>

    </div>
    <!-- /按钮 -->
    <!-- 表格 -->
    <el-table size="large" :data="comment">
      <el-table-column label="序号" type="index" :index="1"></el-table-column>
      <el-table-column label="主题" prop="content" align="center"></el-table-column>
      <el-table-column label="评论时间" prop="commentTime" align="center"></el-table-column>
      <el-table-column label="评论次数" prop="floor" align="center"></el-table-column>
      
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" plain size="small" @click="editHandler(scope.row)">修改</el-button>
          <el-button type="danger" icon="el-icon-delete" plain size="small" @click="deleteHandler(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
    <!-- 模态框 -->


    <!-- /模态框 -->
  </div>
</template>
<script>
import { del , get , post } from '@/utils/request'
export default {
  // 页面数据
  data(){
    return {
        // 用于保存检索的参数
        param:{},
        // param:{id,content},
        //  paramw:{},
        // 组件模板中需要的数据
      comment:[]
    }
  },
  // 所有的方法
  methods:{
    // 跳转 
    editHandler(row){
        // 跳转到修改
        // this
        // 携带当前行
        this.$router.push({
          path:"/comment/create",
          query:row

        })
    },
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/comment/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadComments();
        });
      });
    },

    toAddHandler(){
      this.$router.push("/comment/create")
    },
        // 查询后台中的应用信息
    loadComments(){
      let url = 'http://localhost:8888/comment/query'
      get(url,this.param).then((resp)=>{
        this.comment = resp.data;
      })
    }
  },
   // 页面渲染的时候会调用的函数
  created(){
    this.loadComments();
  }
}
</script>
<style scoped>
.btns {
  margin-bottom: .5em;
}
</style>